package tr.gov.tubitak.bilgem.esya.certviewer.viwerasn;

import sun.security.x509.GeneralName;
import sun.security.x509.GeneralNames;
import sun.security.x509.IssuerAlternativeNameExtension;
import sun.security.x509.SubjectAlternativeNameExtension;
import tr.gov.tubitak.bilgem.esya.certviewer.Bundle;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 08.12.2011
 * Time: 10:17
 * To change this template use File | Settings | File Templates.
 */
public class EIssuerAlternativeNameExtension implements ECertExtension{
    IssuerAlternativeNameExtension issuerAlternativeNameExt;
    @Override
    public String getName() {
        return Bundle.getString("IssuerAlternativeNameExtension.Name");
    }

    @Override
    public String getShortTitle() {
        GeneralNames names = null;
        StringBuilder sb = new StringBuilder();
        try {
            names = (GeneralNames) issuerAlternativeNameExt.get(IssuerAlternativeNameExtension.ISSUER_NAME);
            for(GeneralName name : names.names()){
                sb.append(name);
                sb.append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return sb.toString();
    }

    @Override
    public String getLongTitle() {
        return getShortTitle();
    }

    @Override
    public boolean isCritical() {
        return issuerAlternativeNameExt.isCritical();
    }

    @Override
    public void encode(byte[] data) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setAsnObject(Object asnObject) {
        if(asnObject instanceof IssuerAlternativeNameExtension)
        {
            issuerAlternativeNameExt = (IssuerAlternativeNameExtension) asnObject;
        }
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
